﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.IO;
using WebVideo.Areas.Admin.Models;
using System.Collections;


namespace WebVideo.Areas.Admin.Models
{
    public class TypeNewsModel
    {
        public int Id { get; set; }
        [Required(ErrorMessage = "Tên không được rỗng")]
        public string Name { get; set; }

        
        public static  IEnumerable<EntityTypeNew > LayDuLieu()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            var query = from p in db.EntityTypeNews
                        select p;

            return query.ToList();
        }

        public static void Insert(TypeNewsModel Mtnew)
        {
            dbVideoDataContext db = new dbVideoDataContext();


            EntityTypeNew  tnew = new  EntityTypeNew ();

            tnew.Name  = Mtnew .Name ;

            db.EntityTypeNews.InsertOnSubmit(tnew);
            db.SubmitChanges();

        }


        public static TypeNewsModel LayModel(int IdTypeNews)
        {
            TypeNewsModel Mtnew = new TypeNewsModel();


            dbVideoDataContext db = new dbVideoDataContext();

            EntityTypeNew tnew = db.EntityTypeNews.Where(p => p.Id == IdTypeNews).Single();

            Mtnew.Name = tnew.Name;
            Mtnew.Id = tnew.Id;

            return Mtnew;

        }
        public static void Edit(TypeNewsModel Mtnew)
        {
            dbVideoDataContext db = new dbVideoDataContext();

            EntityTypeNew tnew = db.EntityTypeNews.Where(p => p.Id == Mtnew.Id).Single();
            tnew.Name = Mtnew.Name;
            db.SubmitChanges();

        }

        public static void Delete(int Id)
        {
            dbVideoDataContext db = new dbVideoDataContext();

            EntityTypeNew tnew = db.EntityTypeNews.Where(p => p.Id == Id).Single();
            db.EntityTypeNews.DeleteOnSubmit(tnew);
            db.SubmitChanges();
          
        }

    }
}